﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Zhuang.WinForm.AuthorityManager;

namespace Zhuang.WinForm
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
        

        private void Main_Load(object sender, EventArgs e)
        {
            do_桌面();

        }

        private bool HaveOpened(Form parentForm, string subFormClassName)
        {
            //查看窗口是否已经被打开
            bool bReturn = true;
            for (int i = 0; i < parentForm.MdiChildren.Length; i++)
            {
                if (parentForm.MdiChildren[i].Name == subFormClassName)
                {

                    parentForm.MdiChildren[i].BringToFront();
                    //parentForm.MdiChildren[i].WindowState = FormWindowState.Maximized;
                    bReturn = false;
                    break;
                }
            }
            return bReturn;
        }

        private void 用户权限设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_用户权限设置();
        }

        


        private void 用户管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_用户管理();
        }

        

        private void 菜单管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do_菜单管理();
        }


        private void do_桌面()
        {
            Desktop d = new Desktop();


            if (HaveOpened(this, "Desktop"))
            {
                d.MdiParent = this;
                d.WindowState = FormWindowState.Maximized;
                d.Show();
            }
        }

        private void do_用户管理()
        {
            UserManager um = new UserManager();


            if (HaveOpened(this, "UserManager"))
            {
                um.MdiParent = this;
                //um.StartPosition = FormStartPosition.CenterScreen;
                um.Show();
            }
        }

        private void do_菜单管理()
        {
            MenuManager mm = new MenuManager();


            if (HaveOpened(this, "MenuManager"))
            {
                mm.MdiParent = this;
                //um.StartPosition = FormStartPosition.CenterScreen;
                mm.Show();
            }
        }

        private void do_用户权限设置()
        {
            UserAuthorithSetting sas = new UserAuthorithSetting();


            if (HaveOpened(this, "UserAuthorithSetting"))
            {
                sas.MdiParent = this;
                sas.Show();
            }
        }

        private void 用户权限设置ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {

        }

    }
}
